package com.gitee.dolt.core.util;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.gitee.dolt.utils.EnvUtils;
import org.springframework.context.ApplicationContext;

/**
 * @author LYH
 */
public class SpringUtils extends SpringUtil {

    public static ApplicationContext publishEvent(Object event) {
        ApplicationContext applicationContext = getApplicationContext();
        applicationContext.publishEvent(event);
        return applicationContext;
    }

    public static boolean isDev() {
        String[] activeProfiles = getActiveProfiles();
        return ArrayUtil.contains(activeProfiles, EnvUtils.DEV);
    }

    public static boolean isTest() {
        String[] activeProfiles = getActiveProfiles();
        return ArrayUtil.contains(activeProfiles, EnvUtils.TEST);
    }

    public static boolean isProd() {
        String[] activeProfiles = getActiveProfiles();
        return ArrayUtil.contains(activeProfiles, EnvUtils.PROD);
    }

    public static boolean isDevOrTest() {
        String[] activeProfiles = getActiveProfiles();
        return ArrayUtil.containsAny(activeProfiles, EnvUtils.DEV, EnvUtils.TEST);
    }

}
